package leetcode_0888

/**
 * 1. 暴力破解法
 */
func fairCandySwap1(A []int, B []int) []int {

	tmpHash := map[int]int{}

	lengthA, lengthB := len(A), len(B)
	sumA, sumB := 0, 0

	for i := 0; i < lengthA; i++ {
		sumA += A[i]
		tmpHash[A[i]] = 1
	}

	for i := 0; i < lengthB; i++ {
		sumB += B[i]
	}

	diff := (sumA - sumB) >> 1
	for i := 0; i < lengthB; i++ {
		if _, ok := tmpHash[B[i]+diff]; ok {
			return []int{B[i] + diff, B[i]}
		}
	}

	return []int{}
}
